home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 …ember: Reference Library / Dev.CD Dec 94.toast / Periodicals / develop / develop Issue 15 / develop 15 code / Floating Windows / Sample Source / appleEventHandlers.c next >
Encoding:
Text File  |  1994-10-13  |  5.3 KB  |  183 lines  |  [TEXT/MMCC]

  1. // If the interfaces aren't included yet, do the standard includes. Otherwise, precompiled headers
  2. // have been loaded already, thank you very much
  3. #ifndef __TYPES__
  4.     #include <Types.h>
  5.     #include <AppleEvents.h>
  6.     #include <Desk.h>
  7.     #include <Dialogs.h>
  8.     #include <Editions.h>
  9.     #include <Events.h>
  10.     #include <Menus.h>
  11.     #include <SegLoad.h>
  12.     #include <TextUtils.h>
  13.     #include <ToolUtils.h>
  14.     #include <Windows.h>
  15. #endif
  16.  
  17. #include "FloaterSample.h"
  18. #include "appleEventHandlers.h"
  19. #include "eventHandler.h"
  20. #include "fileMenuRoutines.h"
  21.  
  22. /*    Private routines */
  23.     
  24. pascal    Boolean IdleProc(EventRecord *theEventRecord, long *sleepTime, RgnHandle *mouseRgn);
  25.     
  26. /* Globals */
  27.     
  28. extern Boolean    gDone;                            /* Set to true if user selects Quit */
  29. extern Boolean    gInBackground;                    /* Set to true if app is switched into background */
  30.  
  31. /*    Handle the ‘oapp’ AppleEvent.    */
  32.  
  33. pascal OSErr    OAPPHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  34. {
  35. #pragma unused (reply, handlerRefCon)
  36.  
  37.     OSErr        oappErr;
  38.     AEKeyword    missedKeyWord;
  39.     DescType    actualType;
  40.     Size        actualSize;
  41.     
  42.     oappErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  43.  
  44.     if (!oappErr)                    /* If no error, then a missing parameter was found */
  45.         return errAEParamMissed;
  46.     
  47.     /*    Do whatever needs to be done when starting up and return noErr */
  48.     
  49.     return    noErr;
  50. }
  51.  
  52. /*    Handle the ‘odoc’ AppleEvent.    */
  53.  
  54. pascal OSErr    ODOCHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  55. {
  56. #pragma unused (reply, handlerRefCon)
  57.  
  58.     OSErr            odocErr;
  59.     AEKeyword        missedKeyWord;
  60.     DescType        actualType;
  61.     Size            actualSize;
  62.     AEDescList        documentList;
  63.     long            itemsInList;
  64.     long            i;
  65.     AEKeyword        keyWord;
  66.     DescType        typeCode;
  67.     FSSpec            documentFileSpec;
  68.     TargetID        senderType;
  69.     OSType            senderCreator;
  70.     ProcessSerialNumber    thePSN;
  71.     
  72.     odocErr = AEGetParamDesc(&theAppleEvent, keyDirectObject, typeAEList, &documentList);    /* Get list of documents to open */
  73.     if (odocErr)
  74.         return odocErr;
  75.         
  76.     odocErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  77.  
  78.     if (!odocErr)                    /* If no error, then a missing parameter was found */
  79.         return errAEParamMissed;
  80.     
  81.     /* 
  82.         If we’re in the background, see if the event was sent from the Finder.  If so,
  83.         switch to the front.
  84.     */
  85.     
  86.     if (gInBackground) {
  87.         odocErr = AEGetAttributePtr(&theAppleEvent, keyAddressAttr, typeTargetID, &actualType, (Ptr) &senderType, sizeof(senderType), &actualSize);
  88.         BlockMove((Ptr) (&(senderType.name.u.portTypeStr)+1), (Ptr) &(senderCreator), 4);
  89.         if (senderCreator == 'MACS') {
  90.             thePSN.highLongOfPSN = 0;
  91.             thePSN.lowLongOfPSN = kCurrentProcess;
  92.             SetFrontProcess(&thePSN);
  93.         }
  94.     }
  95.  
  96.     /* Open all the documents in documentList */
  97.     
  98.     odocErr = AECountItems(&documentList, &itemsInList);        /* Get number of documents */
  99.     
  100.     for (i = 1; i <= itemsInList; i++) {
  101.         odocErr = AEGetNthPtr(&documentList, i, typeFSS, &keyWord, &typeCode, (Ptr) &documentFileSpec, sizeof(documentFileSpec), &actualSize);
  102.         DoOpenFile(&documentFileSpec);
  103.     }
  104.         
  105.     odocErr = AEDisposeDesc(&documentList);            /* Dispose of AE structure created by AEGetParamDesc */
  106.     return    noErr;
  107. }
  108.  
  109. /*    Handle the ‘pdoc’ AppleEvent.    */
  110.  
  111. pascal OSErr    PDOCHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  112. {
  113. #pragma unused (reply, handlerRefCon)
  114.  
  115.     OSErr        pdocErr;
  116.     AEKeyword    missedKeyWord;
  117.     DescType    actualType;
  118.     Size        actualSize;
  119.     AEDescList    documentList;
  120.     long        itemsInList;
  121.     long        i;
  122.     AEKeyword    keyWord;
  123.     DescType    typeCode;
  124.     FSSpec        documentFileSpec;
  125.     
  126.     pdocErr = AEGetParamDesc(&theAppleEvent, keyDirectObject, typeAEList, &documentList);    /* Get list of documents to open */
  127.     
  128.     pdocErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  129.  
  130.     if (!pdocErr)                    /* If no error, then a missing parameter was found */
  131.         return errAEParamMissed;
  132.     
  133.     /* Print all the documents in documentList */
  134.     
  135.     pdocErr = AECountItems(&documentList, &itemsInList);        /* Get number of documents */
  136.     
  137.     for (i = 1; i <= itemsInList; i++) {
  138.         pdocErr = AEGetNthPtr(&documentList, i, typeFSS, &keyWord, &typeCode, (Ptr) &documentFileSpec, sizeof(documentFileSpec), &actualSize);
  139.         DoPrintFile(&documentFileSpec);
  140.     }
  141.         
  142.     pdocErr = AEDisposeDesc(&documentList);                    /* Dispose of AE structure created by AEGetParamDesc */
  143.     return    noErr;
  144. }
  145.  
  146. /*    Handle the ‘quit’ AppleEvent.    */
  147.  
  148. pascal OSErr    QUITHandler(AppleEvent theAppleEvent, AppleEvent reply, long handlerRefCon)
  149. {
  150. #pragma unused (reply, handlerRefCon)
  151.  
  152.     OSErr        quitErr;
  153.     AEKeyword    missedKeyWord;
  154.     DescType    actualType;
  155.     Size        actualSize;
  156.     
  157.     quitErr = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr, typeWildCard, &actualType, (Ptr) &missedKeyWord, sizeof(missedKeyWord), &actualSize);
  158.  
  159.     if (!quitErr)                    /* If no error, then a missing parameter was found */
  160.         return errAEParamMissed;
  161.     
  162.     /*    Do whatever needs to be done when quitting and return noErr */
  163.     
  164.     gDone = true;    
  165.     return    noErr;
  166. }
  167.  
  168. pascal    Boolean IdleProc(EventRecord *theEventRecord, long *sleepTime, RgnHandle *mouseRgn)
  169. {    
  170.     switch (theEventRecord->what) {
  171.         case updateEvt:
  172.         case activateEvt:
  173.         case osEvt:            HandleEvent(theEventRecord);
  174.                             break;
  175.         case nullEvent:        *mouseRgn = nil;
  176.                             *sleepTime = 15;
  177.                             break;
  178.     }
  179.     return false;
  180. }
  181.  
  182.  
  183.